package com.mark.common.exception;


import com.mark.common.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: 全局异常的处理
 * @Author: Mark
 * @CreateDate: 2018/10/9 17:40
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Campuso2oException.class)
    @ResponseBody
    public ServerResponse<String> handleCampuso2oException(Campuso2oException e){
        log.error("[全局异常之Campuso2oException->]"+e.getMessage());
        return  ServerResponse.createByException("后台处理业务过程发生了异常");
    }


    @ExceptionHandler(value = DataException.class)
    @ResponseBody
    public ServerResponse<String> handleDataException(DataException e){
        return  ServerResponse.createByErrorMessage(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ServerResponse<String> handleException(Exception e){
        log.error("[全局异常之其他异常->]"+e.getMessage());
        return  ServerResponse.createByException("后台发生了尚不明确的异常");
    }
}
